#!/usr/bin/python2
# -*- coding: latin-1 -*-
import sys
from sys import argv
from locale import *
import SOAPpy
from SOAPpy import *
from ctypes import *

#SOAPpy.Config.debug = 1
api = SOAPpy.SOAPProxy(
	"localhost:8888",
	namespace = "urn:netbook",
	)

def uint32(i):
    return unsignedIntType(i)
def uint64(i):
    return unsignedLongType(i)
def latin(i):
    return i.encode("latin-1")

def user_dump(user):
    print "User:"
    print "id:",user.id
    print "nickname:",user.nickname
    print "mail:",user.mail
    print "time_reg:",user.time_reg
    print "time_lastlogin:",user.time_lastlogin
    print "time_lastupdate:",user.time_lastupdate
    print "attribute:",user.attribute

def note_dump(note):
    print "Note:"
    print "id:",note.id
    print "owner_id:",note.owner_id
    print "uuid:",note.uuid
    print "title:",note.title
    print "content:",note.content
    print "time_create:",note.time_create
    print "time_lastupdate:",note.time_lastupdate
    print "version:",note.version
    print "attribute:",note.attribute

if __name__ == '__main__':
    try:
	new_user = api.register(mail="python@python.com",passwd="python123")
    except SOAPpy.faultType as ft:
	print ft
    else:
	user_dump(new_user)
    try:
	session = api.login(mail="python@python.com",passwd="python123")
    except SOAPpy.faultType as ft:
	print type(ft),ft.faultstring
    else:
	user = api.getMyself(session=session)
	user_dump(user)
    userlist = api.getUserList(session=session)
    for u in userlist:
	user_dump(u)
    api.changeMyNickname(session=session, nickname="py")
    user = api.getMyself(session=session)
    user_dump(user)
    #add a note
    new_note = api.insertMyNote(session=session,title="pytitle",content="pycontent")
    note_dump(new_note)
    num = api.getAllPublicNoteNumber(session=session)
    print type(num),num
    #note_list = api.getAllPublicNoteList(session=session,start=uint64(0),count=uint32(18),field=uint32(1023))
    #for n in note_list:
#	note_dump(n)
    api.logout(session=session)
